// Copyright (c) 2020 Presto Labs Pte. Ltd.
// Author: donggu

#pragma once

#include <experimental/filesystem>
#include <string>

#include <mlpack/core.hpp>
#include <mlpack/methods/linear_regression/linear_regression.hpp>

#include "coin2/strategy/strategy.h"
#include "presto/quant/math/moving_average.h"
#include "presto/quant/math/moving_window.h"

using presto::math::TimeWindowMovingAverage;

class MlpackLinear {
  explicit MlpackLinear(const std::experimental::filesystem::path& path) {
    mlpack::data::Load(path, "logistic_regression_model", impl_);
  }

  void Predict() {
    arma::mat data;
    arma::rowvec predictions;
    data.row(0) = 0;
    impl_.Predict(data, predictions);
  }

  mlpack::regression::LinearRegression impl_;
};

// Y: future latency average in the next 10ms, 20ms, 30ms  (>=100ms is meaningless, it's flat)

class MlpackLinearLatencyModel : public coin2::strategy::IStrategy {
  explicit MlpackLinearLatencyModel(
      const std::experimental::filesystem::path& path,
      const std::string& target_symbol)
      : impl_(path), target_symbol_(target_symbol) {}

  void onTradeUpdate(const FeedUpdate& upd) {
    if (upd.product().absolute_norm() != target_symbol_) {
      return;
    }
  }

 private:
  MlpackLinear impl_;
  std::string target_symbol_;
  double features_10ms_[Feature::NUM_FEATURE];
  double features_20ms_[Feature::NUM_FEATURE];
  double features_30ms_[Feature::NUM_FEATURE];

  //
};
